package com.soul.dj.util.http;

import java.net.FileNameMap;
import java.net.URLConnection;

/**
 * @author
 * @ClassNmae MediaType
 * @create 2018-09-13 20:47
 **/
public class MediaType {

    public static final okhttp3.MediaType JSON
            = okhttp3.MediaType.parse("application/json; charset=utf-8");
    public static final okhttp3.MediaType FORMD_DATA_MULTIPART
            = okhttp3.MediaType.parse("multipart/form-data; charset=utf-8");
    public static final okhttp3.MediaType FORMD_DATA
            = okhttp3.MediaType.parse("application/x-www-form-urlencoded; charset=utf-8");


    public static okhttp3.MediaType getMimeType(String filename) {
        FileNameMap filenameMap = URLConnection.getFileNameMap();
        String contentType = filenameMap.getContentTypeFor(filename);
        if (contentType == null) {
            contentType = "application/octet-stream"; //* exe,所有的可执行程序
        }
        return okhttp3.MediaType.parse(contentType);
    }

}
